package com.whmnx.chitchat.view;

import android.app.Dialog;
import android.content.Context;

import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.whmnx.chitchat.R;
import com.whmnx.chitchat.utils.KeyboardUtils;
import com.whmnx.chitchat.utils.UItils;

import java.util.List;


/**
 *
 * @author Administrator
 * @date 2019/1/14
 */

public class DynamicInputTextMsgDialog extends Dialog {

    private RecyclerView rvImg;
    private EditText etInputMessage;
    private TextView tvSend;
    private LinearLayout rlOutsideView;

   // private ImageAdapter imageAdapter;
    private View vXian;
    private List<String> img;
    private OnSendClickListener onSendClickListener;

    public enum TYPE{
        NO_IMG,
        IMG
    }


    public DynamicInputTextMsgDialog(@NonNull Context context) {
        super(context, R.style.dialog);
        setContentView(R.layout.dialog_dynamic_input);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        tvSend = findViewById(R.id.tv_send);
        rlOutsideView = findViewById(R.id.rl_outside_view);
        etInputMessage = findViewById(R.id.et_input_message);

        tvSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //发送
                if (onSendClickListener != null){
                    if (TextUtils.isEmpty(etInputMessage.getText().toString())){
                        UItils.showToastSafe(etInputMessage.getHint().toString());
                        return;
                    }
                    onSendClickListener.onSendClick(etInputMessage.getText().toString());
                    KeyboardUtils.hideKeyBoard(getContext(),view);
                    dismiss();
                }
            }
        });

        rlOutsideView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                KeyboardUtils.hideKeyBoard(getContext(),view);
                dismiss();
            }
        });
    }

    public void setShowType(){
          //  vXian.setVisibility(View.VISIBLE);
          //  rvImg.setVisibility(View.VISIBLE);
        KeyboardUtils.showKeyBoard(getContext(),getCurrentFocus());
        etInputMessage.setText("");
        show();
    }


    public void setOnSendClickListener(OnSendClickListener onSendClickListener) {
        this.onSendClickListener = onSendClickListener;
    }

    public void setImg(List<String> img) {
        this.img = img;
      //  imageAdapter.addFirstDataSet(img);
    }

    public interface OnSendClickListener{
        void onSendClick(String text);
    }
}
